//D:\mingw_project\v8test>g++ -o hw.exe -Iinclude -m32 -O2  -fno-rtti -fno-exceptions -DUSING_V8_SHARED hw.cpp  -L. -lv8 -lwinmm -lws2_32
#include "v8.h"
#include <string>
#include <iostream>

using namespace std;using namespace v8;


int main(int argc, char* argv[]) {
char * jscode=
  
  "ball=['0','2','3','14','33'];"
  "result=''";
  " function test()"
  "{"
 "for(i=0;i<ball.length;i++)"
 " {"
 " result=result+ball[i]+',';"
 " }"
 "return result;}"
 "var ts = test();"
 ;

  // Create a stack-allocated handle scope.
  HandleScope handle_scope;

  // Create a new context.
  Persistent<Context> context = Context::New();
  
  // Enter the created context for compiling and
  // running the hello world script. 
  Context::Scope context_scope(context);

  // Create a string containing the JavaScript source code.
  Handle<String> source = String::New(jscode);

  // Compile the source code.
  TryCatch tryCatch; 
  Handle<Script> script = Script::Compile(source);
  if(script.IsEmpty())   
    {       
        String::Utf8Value error(tryCatch.Exception());       
        cout<<*error<<endl;       
        return 1;   
    } 
  // Run the script to get the result.
  Handle<Value> result = script->Run();
   Handle<String> js_data = String::New("ts");
 Handle<Value> js_data_value = context->Global()->Get(js_data);
  // Dispose the persistent context.
  context.Dispose();

  // Convert the result to an ASCII string and print it.
  String::AsciiValue ascii(result);
  printf("result:%s\n", *ascii);
  String::AsciiValue  ascii2(js_data_value);
  printf("result:%s\n", *ascii2);
  return 0;
}